home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / docs / linux-do / programm / lpg-0.4 / lpg-0 / LPG / examples / checklp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-15  |  1.8 KB  |  68 lines

  1. /*
  2.  *  AUTHOR: Sven Goldt (goldt@math.tu-berlin.de)
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of the GNU General Public License
  6.  *  as published by the Free Software Foundation; either version 2
  7.  *  of the License, or (at your option) any later version.
  8.  *
  9.  *  This program is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14. */
  15. /*
  16.  *
  17.  * Changes in 1.1: Fixed bit meaning for low active lines ! 
  18.  *
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23. /* #include <linux/lp.h>  DAMNED ! - Some butthead crippled that file !!! */
  24. #include "oldlp.h"
  25. #include <asm/io.h>
  26.  
  27. #ifndef LP_NO
  28. #define LP_NO 3
  29. #endif
  30.  
  31. main()
  32. {
  33. int i,fd,irq;
  34. unsigned char status=0;
  35. char printer[10];
  36.  
  37.  for (i=0;i<LP_NO;i++)
  38.  {
  39.   sprintf(printer,"/dev/lp%d",i);
  40.   printf("\nchecking %s: ",printer);
  41.   fflush(stdout);
  42.  
  43.   fd=open(printer,O_WRONLY);
  44.   if (fd<0) { perror(NULL); continue; }
  45.   irq=ioctl(fd,LPGETIRQ,0);
  46.   close(fd);
  47.   if (irq<0)  { perror(NULL); continue; }
  48.   if (irq>0) printf("irq = %d\n",irq);
  49.   else printf("polling driver used\n");
  50.  
  51.   printf(" I/O base address is 0x%x for %s\n",LP_B(i),printer);
  52.   if (ioperm(LP_B(i)+1,1,1)<0)
  53.   {
  54.    printf("access to port 0x%x denied\n",LP_B(i)+1);
  55.    continue;
  56.   }
  57.   status=inb(LP_B(i)+1);
  58.   printf(" printer is%sand%sbusy\n",
  59.                             (status & LP_PSELECD) ? " online " : " offline ",
  60.                             (status & LP_PBUSY) ? " not " : " ");
  61.   printf(" printer is%swaiting for datas\n",(status & LP_PACK) ? " not " : " ");
  62.   printf(" paper is%sempty\n",(status & LP_POUTPA) ? " " : " not ");
  63.   printf(" printer is signalling%serror\n",
  64.                                     (status & LP_PERRORP) ? " no " : " an ");
  65.  }
  66. }
  67.  
  68.